package com.scopionstudio.newpaper;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

import com.google.ads.AdRequest;
import com.google.ads.AdView;
import com.google.analytics.tracking.android.EasyTracker;
import com.scopionstudio.adapter.NewsAdapter;
import com.scopionstudio.bean.Variables;
import com.scopionstudio.utils.RessItems;

public class ShowInfo extends ScopionActivity implements OnItemClickListener {
	private int paper = 0;
	private int positions = 0;
	private ListView mList = null;
	private NewsAdapter adapter;
	private ArrayList<RessItems> items;
	private static String TAG = "ShowInfo";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layoutshowinfo);
		initVariable();
		try {
			Bundle bundle = getIntent().getExtras();
			positions = bundle.getInt(Variables.CATEGORY);
			paper = bundle.getInt(Variables.PAPER);
			// key is random value
			int key = paper * 1000 + positions;
			items = Variables.newMap.get(key);
			if (items != null) {
				setTitle("" + Variables.Categories[paper][positions]);
				adapter = new NewsAdapter(this, Variables.ICONS[paper], items);
				mList.setAdapter(adapter);
			} else {
				Toast.makeText(getParent(),
						getResources().getString(R.string.ms_null_data),
						Toast.LENGTH_SHORT).show();
			}

		} catch (Exception e) {
			Log.e("Error showinfo :", e.toString());
		}
	}
	public void initVariable() {
		mList = (ListView) findViewById(R.id.listShow);
		mList.setOnItemClickListener(this);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
		try {
			Intent intent = new Intent(ShowInfo.this, WebviewLink.class);
			intent.putExtra(Variables.LINK, items.get(position).getLink());
			intent.putExtra(Variables.CATEGORY, positions);
			intent.putExtra(Variables.PAPER, paper);
			startActivity(intent);
			finish();
		} catch (Exception e) {
			Log.e("Error", e.toString());
		}
	}

	@Override
	public void onBackPressed() {
		Intent mIntent = new Intent(ShowInfo.this, CategoryActivity.class);
		startActivity(mIntent);
		finish();
	}

    @Override
    protected void onStop() {
        super.onStop();
        EasyTracker.getInstance(getApplicationContext()).activityStop(this);
    }

    @Override
    protected void onStart() {
        super.onStart();
        EasyTracker.getInstance(getApplicationContext()).activityStart(this);
    }
}
